<?php

class Core_Global
{

    /**
     * 
     * @var Zend_Config
     */
    private static $_config = null;
    
    /**
     * 
     * @var Zend_Db
     */
    private static $_database = null;
    
    private static $_cache = null;

    /**
     * Get configuration
     * @return array
     */
    public static function getConfig()
    {
        if (self::$_config === null)
        {
            self::$_config = new Zend_Config_Ini(APPLICATION_PATH . DS . 'configs' . DS . 'global.ini', APPLICATION_ENV);                  
        }

        return self::$_config;
    }

    public static function getDatabase()
    {
        if (self::$_database === null)
        {            
            self::$_database = new Zend_Db_Adapter_Pdo_Mysql(self::getConfig()->database);
            self::$_database->setFetchMode(Zend_Db::FETCH_ASSOC);
        }

        return self::$_database;
    }        
    
    public static function getCache()
    {
    	if (self::$_cache === null)
    	{    	
    		self::$_cache = new Core_NoSQL_Memcache();
    		
    		$config = self::getConfig()->cache;
    		
    		self::$_cache->connect($config->host, $config->port);
    	}
    	
    	return self::$_cache;
    }

}